package com.cn.ryc.controller;

import com.cn.ryc.model.Alarm;
import com.cn.ryc.service.AlarmService;
import com.cn.ryc.util.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/safety")
public class AlarmController {

    @Autowired
    private AlarmService alarmService;

    @GetMapping("/alarms")
    // 获取所有警报
    public ResponseEntity<ApiResponse<List<Alarm>>> getAllAlarms() {
        return alarmService.getAllAlarms();
    }

    @PostMapping("/alarm/status")
    public ResponseEntity<ApiResponse<String>> updateAlarmStatus(@RequestBody Map<String, Object> request) {
        Long id = Long.valueOf(request.get("id").toString());
        Boolean processed = (Boolean) request.get("processed");
        return alarmService.updateAlarmStatus(id, processed);
    }

    @GetMapping("/alarm/types")
    public ResponseEntity<ApiResponse<List<String>>> getAlarmTypes() {
        return alarmService.getAlarmTypes();
    }

    @GetMapping("/alarm/levels")
    public ResponseEntity<ApiResponse<List<String>>> getAlarmLevels() {
        return alarmService.getAlarmLevels();
    }

//    插入新报警信息
    @PostMapping("/alarm/insert")
    public ResponseEntity<ApiResponse<String>> insertAlarmInfo(@RequestBody Map<String, Object> request) {
        return alarmService.insertAlarmInfo(request);
    }


} 